

/* Model */

/* View */

var WindGrid = new Object();

WindGrid.createView = function(model) {
	var container = new WindView();
	container.setCssClass("WindGrid");
	
	var borderWidth = 1;
	
	var columns = model.getColumns();
	var rows = model.getRows();

	var totalWidth = 0;
	var totalHeight = 0;
	
	var x = 0;
	var y = 0;
	
	for(var c=0; c<columns; c++) {
		
		var column = new WindView();
		column.setCssClass("WindGridColumn");
		var columnWidth = model.getColumnWidth(r);
		var columnHeight = 0;
		column.setX(x);
		column.setWidth(columnWidth);

		y = 0;	
			
		for(var r=0; r<rows; r++) {

			var rowHeight = model.getRowHeight(r);
			
			var cell = new WindView();
			cell.setCssClass("WindGridCell");
			cell.setX(0);
			cell.setY(y);
			cell.setHeight(rowHeight);
			cell.setWidth(columnWidth);
			
			if(model.getCellAt!=null) {
				var customCell = model.getCellAt(r,c);
				if(customCell!=null) {
					cell.addView(customCell);
				}
			}
			
			column.addView(cell);
			
			columnHeight += rowHeight;
			columnHeight += borderWidth;
			
			y += rowHeight;
			y += borderWidth;
		}
		
		column.setHeight(columnHeight - borderWidth);
		container.addView(column);
		
		totalWidth += columnWidth;
		if(c==0) {
			totalWidth += (borderWidth*2);
		} else {
			totalWidth += (borderWidth*1);
		}
		
		totalHeight = columnHeight;
		
		x += columnWidth;
		if(c==0) {
			x += (borderWidth*2);
		} else {
			x += (borderWidth*1);
		}

	}
	
	container.setWidth(totalWidth);
	container.setHeight(totalHeight + borderWidth);
	
	return container;
}
